package com.order.mapper;

import com.order.hit.crossover.platform.common.dao.OrderDao;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Lei
 * @version 0.1
 * @date 2020/8/4
 */
public interface OrderMapper {
    @Select("SELECT * FROM orders")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "orderType", column = "order_type"),
            @Result(property = "orderState", column = "order_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "price", column = "expected_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time")
    })
    public List<OrderDao> getAllorder();

    @Select("SELECT * FROM orders WHERE order_type = #{string}")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "orderType", column = "order_type"),
            @Result(property = "orderState", column = "order_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "price", column = "expected_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time")
    })
    public List<OrderDao> getAllOrderOfOneType(@Param("string") String string);

    @Select("SELECT * FROM orders where store_id=#{storeId}")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "orderType", column = "order_type"),
            @Result(property = "orderState", column = "order_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "price", column = "expected_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time")
    })
    public List<OrderDao> getAllstoreId(@Param("storeId")String storeId);

    @Select("SELECT * FROM orders WHERE order_id = #{id}")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "orderType", column = "order_type"),
            @Result(property = "orderState", column = "order_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "price", column = "expected_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time")
    })
    public OrderDao getOrderDaoByid(@Param("id") String id);

    @Insert("Insert into orders" +
            "(order_id, order_type, order_state, " +
            "store_id, store_name, store_location, " +
            "goodId, good_name, good_type, spec, wholeSalePrice, retailPrice, validDate, " +
            "expected_price, good_number, start_time, end_time) " +
            "VALUES" +
            "(#{orderId}, #{orderType}, #{orderState}," +
            " #{storeId}, #{storeName}, #{storeLocation}, " +
            "#{goodId}, #{goodName}, #{goodType}, #{spec}, #{wholeSalePrice}, #{retailPrice}, #{validDate}, " +
            "#{price}, #{goodNumber}, #{start_time}, #{end_time})")
    @Results({
            @Result(property = "orderId", column = "order_id"),
            @Result(property = "orderType", column = "order_type"),
            @Result(property = "orderState", column = "order_state"),
            @Result(property = "storeId", column = "store_id"),
            @Result(property = "storeName", column = "store_name"),
            @Result(property = "storeLocation", column = "store_location"),
            @Result(property = "goodId", column = "goodId"),
            @Result(property = "goodName", column = "good_name"),
            @Result(property = "goodType", column = "good_type"),
            @Result(property = "spec", column = "spec"),
            @Result(property = "wholeSalePrice", column = "wholeSalePrice"),
            @Result(property = "retailPrice",column = "retailPrice"),
            @Result(property = "validDate", column = "validDate"),
            @Result(property = "price", column = "expected_price"),
            @Result(property = "goodNumber", column = "good_number"),
            @Result(property = "start_time", column = "start_time"),
            @Result(property = "end_time", column = "end_time")
    })
    void insertoneOrder(OrderDao orderDao);


    @Update("update orders set " +
            "order_type=#{orderType}, order_state=#{orderState}, " +
            "store_id=#{storeId}, store_name=#{storeName}, store_location=#{storeLocation}, " +
            "goodId=#{goodId}, good_name=#{goodName}, good_type=#{goodType}, spec=#{spec}, wholeSalePrice=#{wholeSalePrice}, retailPrice=#{retailPrice}, validDate=#{validDate}, " +
            "expected_price=#{price},  good_number=#{goodNumber}, start_time=#{start_time}, end_time=#{end_time} " +
            "where order_id = #{orderId}")
    void updateOrder(OrderDao orderDao);


    @Delete("delete from orders where order_id=#{order_id}")
    void deleteOrderId(@Param("order_id")String order_id);
}
